﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.IO;

public partial class cms_Admin_Printer_p_Danhgiacongnhan : System.Web.UI.UserControl
{
    string uID = "";
    string adm = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["uid"] != null) { uID = Session["uid"].ToString(); }
        if (Session["adm"] != null) { adm = Session["adm"].ToString(); }
        if (!IsPostBack) { ViewAsslist(); }
    }
    #region[ViewAsslist]
    void ViewAsslist()
    {
        List<tbAssessmentDATA> list = new List<tbAssessmentDATA>();
        if (adm == "1")
        {
            list = tbAssessmentDB.tbAssessment_GetByAdmin_CN();
        }
        else
        {
            list = tbAssessmentDB.tbAssessment_GetByCN(uID);
        }
        rptDanhsach.DataSource = list;
        rptDanhsach.DataBind();
        for (int i = 0; i < list.Count; i++)
        {
            Label lblorder = (Label)rptDanhsach.Items[i].FindControl("lblorder");
            int k = (i + 1);
            lblorder.Text = k.ToString();
        }
        list.Clear();
        list = null;
    }
    #endregion
    #region[FormatDate]
    protected string FormatDate(DateTime date)
    {
        try
        {
            if (date.ToString().Trim().Length > 0)
            {
                if (DateTime.Parse(date.ToString()).Year != 1900)
                {
                    string Chuoi = "Tháng " + date.Month.ToString();
                    return Chuoi;
                    //return ((DateTime)date).ToString("dd/MM/yyyy");
                }
                else
                {
                    return "";
                }
            }
            else
            {
                return "";
            }
        }
        catch { return date.ToString(); }
    }
    protected string FormatDateHH(DateTime date)
    {
        try
        {
            if (date.ToString().Trim().Length > 0)
            {
                if (DateTime.Parse(date.ToString()).Year != 1900)
                {
                    return ((DateTime)date).ToString("dd/MM/yyyy hh:mm:ss");
                }
                else
                {
                    return "";
                }
            }
            else
            {
                return "";
            }
        }
        catch { return date.ToString(); }
    }
    #endregion
    #region[Print]
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton1.Visible = false;
        Response.ContentType = "application/vnd.ms-excel";
        Response.ContentEncoding = System.Text.UnicodeEncoding.UTF8;
        Response.AddHeader("Content-Disposition", "attachment; filename=Chamdiemdanhgiacongnhan.xls");
        StringWriter stringWriter = new StringWriter(); //System.IO namespace should be used
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        this.RenderControl(htmlTextWriter);
        Response.Write(stringWriter.ToString());
        Response.End();
    }
    #endregion
}
